import logging

import allure
import jsonpath

from utils.send_request import send_jdbc_request

@allure.step("http响应断言")
def http_assert(case,res):
    if case["check"]:
        result=jsonpath.jsonpath(res.json(), case["check"])[0]
        logging.info(f"3、JSON断言，响应结果({result})==预期结果({case["expected"]})")
        assert  result == case["expected"]
    else:
        assert case["expected"] in res.text


def json_assert(case,res):
    if case["sql_check"] and case["sql_expected"]:
        result=send_jdbc_request(case["sql_check"])
        logging.info(f"3、JDBC断言，响应结果({result}) == 预期结果({case["sql_expected"]})")
        with allure.step("数据库响应断言"):
            assert result == case["sql_expected"]